<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script type="text/javascript" src="./plugins/vue/dist/vue.min.js"></script>
    <script type="text/javascript" src="./plugins/axios/dist/axios.min.js"></script>
    <!--引入公共的js-->
    <script type="text/javascript" src="./js/common.js"></script>
</head>
<body>
    <div id="app"></div>
</body>
<script>
    new Vue({
        el:"#app",
        mounted(){
            //获取当前页面?后面的参数，最终封装成一个json对象
            let param = getParam();
            this.$http.post("/wechat/handleCallback",param).then(res=>{
                let {success,msg,resultObj} = res.data
                //如果success为true and resultObj有值 没有绑定
                if (success&&resultObj.openid){
                    //跳转到绑定页面
                    location.href="/binder.html?openid="+resultObj.openid
                }else if (success&&resultObj.token){
                    //已经绑定 直接登录 跳转首页 并将token 和 loginUser 保存在浏览器
                    localStorage.setItem("token",resultObj.token)
                    //将loginUser转成对象
                    localStorage.setItem("loginUser",JSON.stringify(resultObj.loginUser))
                    location.href="/index.html"

                }
            })
        }
    })
</script>
</html>